<?php
/*
	会员管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'dian_mid'=>$_SESSION['uid']);
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'createtime desc',
	);
	$list=$this->get_list('member',$parameter,$total);
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['agenttime']=date('Y-m-d H:i:s',$item['agenttime']);
			$item['saleorderfee']=$this->getsum('order',array('sale_id'=>$item['mid']),'order_price');
			$item['saleordernum']=$this->count('order',array('sale_id'=>$item['mid']),'id');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['agent_status']=$this->agent_status;
	$return['yewunum']=$this->count('member',array('dian_mid'=>$_SESSION['uid']),'mid');
	$return['levels']=$this->getall('level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['levels']['0']=array('id'=>'0','title'=>'默认等级');
	$return['types']=array(
		'0'=>'普通会员',
		'1'=>'经销商',
	);
	exi($return);
}
if($_RQ['op']=='add'){
	$id=intval($_RQ['id']);
	if($id){
		$item=$this->get('member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
    $return['item']=$item;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'dian_mid'=>intval($postdata['dian_mid']),
		'is_agent'=>1,
		'agenttime'=>TIMESTAMP,
	);
	$mid=intval($postdata['mid']);
	if($mid){
		$this->update('member',$data,array('mid'=>$mid));
		exi('设置成功！','','list');
	}else{
		exi('请设置业务员！','error');
	}
}
?>